"""
file: logger.py
Author: 城下秋草
Desc: 日志处理模块
"""
import logging
import os.path
from datetime import datetime
from pom.util.paths import log_dir

log_name = f"test_{datetime.now().strftime("%Y%m%d")}.log"
class Log:
    def __init__(self,path=log_dir,name=log_name):
        self.logger = logging.getLogger("秋草日志")
        self.logger.setLevel(logging.DEBUG)
        fileHandler = logging.FileHandler(os.path.join(path,name),encoding="utf-8")
        log_fmt = "[%(levelname)s]%(asctime)s-%(module)s: %(message)s"
        date_fmt = "%H:%M:%S"
        formatter = logging.Formatter(fmt=log_fmt,datefmt=date_fmt)
        fileHandler.setFormatter(formatter)
        self.logger.addHandler(fileHandler)

        cmdHandler = logging.StreamHandler()
        cmdHandler.setFormatter(formatter)
        self.logger.addHandler(cmdHandler)

    @property
    def log(self):
        return self.logger

logger = Log().log